#### FOR FIGURE S12 IN THE SUPPLEMENTARY MATERIAL:
rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
#install.packages("extrafont")
library(extrafont)
#install.packages("performance")
library("performance")
library("see")
library("haven")
library("tidyverse")
######### Placebow/Starbucks -------

setwd("~/Dropbox/Side projects/BET HOUSES PROJECT/data/Gambling_Replication_Materials/Estimates")
setwd("/Users/sergimartinez/Dropbox/EUI/BET HOUSES PROJECT/data/estimates_050121/")

all <- read_dta("star1.dta")

all$id2 <- factor(all$id2,
                  levels = c(0,1,2),
                  labels = c("Overall Average","Below average", "Above average"))

all$y2 <- factor(all$variable,
                 levels = c(0,1),
                 labels = c("Binary var: <500m. = 1",
                            "Distance to closest Starbucks (Logged)"))

theme_results <- theme_bw(base_size = 15) +
  theme(text=element_text(family="Times",
                          size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15, color = "black"),
        axis.title.y = element_text(size = 15, color = "black"),
        axis.title.x = element_text(size = 15, color = "black"),
        legend.position = "top",
        legend.key.size = unit(1.2, "cm"),
        legend.text = element_text(size = 15),
        legend.title = element_text(size = 15),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        strip.text.y.right = element_text(angle = 0))

palette2 = c("black", "blue", "red")

figureS12 <- all %>%
  ggplot(aes(x = y2, y = coef, colour = id2)) +   
  geom_point(size = 2 ,position = position_dodge(.5)) +
  geom_errorbar(aes(ymax = ci_upper95, ymin = ci_lower95), width = 0,  size = .7, position = position_dodge(width = .5)) +
  geom_errorbar(aes(ymax = ci_upper90, ymin = ci_lower90), width = 0, size = 1.6, position = position_dodge(width = .5)) +
  scale_color_manual(name = "Neighborhood\nby income levels:",values = palette2)+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black") + 
  xlab("") +
  ylab("Effect of Starbucks on educational performance") +
  theme_results +
  facet_wrap(y2~., scales="free",nrow=1)+
  #coord_flip() +
  theme(strip.background =element_rect(fill="white"),
        axis.title.y = element_text(size = 15, color = "black"),
        legend.position = "bottom")
figureS12
#ggsave("150121_placebo_starbucks.png", plot = figureS12, width = 35, height = 20, units = "cm")